package fp.poczadly.client.view;

import java.util.List;

import com.google.gwt.cell.client.TextCell;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.cellview.client.AbstractHasData;
import com.google.gwt.user.cellview.client.CellList;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

import fp.poczadly.client.presenter.ChatPresenter;
import fp.poczadly.shared.Utils;

public class ChatView extends Composite implements ChatPresenter.Display {

	private CellList<String> messageList;
	
	private CellList<String> userList;
	
	private TextBox messageTextField;
	
	private Button sendMessageButton;
	
	private Button logoutButton;
	
	public ChatView() {
		VerticalPanel vPanel = new VerticalPanel();
		
		HorizontalPanel hPanel = new HorizontalPanel();
		TextCell messageCell = new TextCell();
		messageList = new CellList<String>( messageCell );
		messageList.setWidth( "300" );
		
		TextCell userCell = new TextCell();
		userList = new CellList<String>( userCell );
		userList.setWidth( "150" );
		
		hPanel.add( messageList );
		hPanel.add( userList );
		
		HorizontalPanel buttonPanel = new HorizontalPanel();
		messageTextField = new TextBox();
		sendMessageButton = new Button( Utils.SEND );
		logoutButton = new Button( Utils.LOG_OUT );
		
		buttonPanel.add( messageTextField );
		buttonPanel.add( sendMessageButton );
		buttonPanel.add( logoutButton );
		
		vPanel.add( hPanel );
		vPanel.add( buttonPanel );
		
		this.initWidget( vPanel );
	}

	@Override
	public HasValue<String> messageTextField() {
		return messageTextField;
	}

	@Override
	public HasClickHandlers sendMessageButton() {
		return sendMessageButton;
	}

	@Override
	public void setMessageListData( List<String> data ) {
		messageList.setRowData( data );
	}

	@Override
	public AbstractHasData<String> messageList() {
		return messageList;
	}
	
	@Override
	public AbstractHasData<String> userList() {
		return userList;
	}

	@Override
	public HasClickHandlers logoutButton() {
		return logoutButton;
	}
}
